<?php

/**
 * @author Du Dan
 * @copyright 2013
 */

class Category extends CWidget
{
    public function init()
    {
        parent::init();
    }

    public function run()
	{
		// Get list categories
		$categories = Categories::model()->findAll('status="A" AND parent_id=0 ORDER BY position DESC');
		foreach ($categories as $category) {
			if (!empty($category->categories)) {
				foreach ($category->categories as $childCategory) {
					$items[] = array(
						'label'=>$childCategory->title,
						'url'=>array('/Events/categories/view', 'url'=>$childCategory->url),
						'linkOptions'=>array('title'=>'Xem sự kiện trong ' . $childCategory->title),
					);
				}
				$categoriesArr[] = array(
					'label'=>$category->title,
					'url'=>array('/Events/categories/view', 'url'=>$category->url),
					'linkOptions'=>array('title'=>'Xem sự kiện trong ' . $category->title),
					'items'=>$items,
				);
				unset($items);
			}
			else {
				$categoriesArr[] = array(
					'label'=>$category->title,
					'url'=>array('/Events/categories/view', 'url'=>$category->url),
					'linkOptions'=>array('title'=>'Xem sự kiện trong ' . $category->title),
				);
			}
		}
    	$this->render('category', array(
			'model'=>$categoriesArr
		));
    }
}

?>